<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script src="${ctxStatic}/jquery/jquery-1.9.1.min.js"></script>
<script src="${ctxStatic}/jquery/keyboard.js"></script>
<html>
<head>
<%@ include file="/WEB-INF/views/include/head.jsp"%>
<link rel="stylesheet" href="${ctxStatic}/css/list_erp.css">
<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
<link rel="stylesheet" href="${ctxStatic}/css/keyboard_style.css">
<style>
	table {
		margin-top: 40px;
		margin-left: 20px;
		border-collapse: separate;
		border-spacing: 0;
		border: 2px #000;
		text-align: center;
        /* margin: 0 auto; */
	}
	table thead tr,table tbody tr {
		height: 50px;
		line-height: 50px;
	}
	table tr th:first-child,table tr td:first-child {/*设置table左边边框*/
		border-left: 2px solid #eaeaea;
	}
	table tr th:last-child,table tr td:last-child {/*设置table右边边框*/
		border-right: 2px solid #eaeaea;
	}
	table tr td:first-child,
	table tr td:nth-child(2),
	table tr td:nth-child(3),
	table tr td:last-child{/*设置table表格每列底部边框*/
		border-bottom: 2px solid #eaeaea;
	}
	table tr th {
		background: #eaeaea;
	}
	table tr:first-child th:first-child {
		border-top-left-radius: 12px;
	}

	table tr:first-child th:last-child {
		border-top-right-radius: 12px;
	}
	table tr:last-child td:first-child {
		border-bottom-left-radius: 12px;
	}

	table tr:last-child td:last-child {
		border-bottom-right-radius: 12px;
	}
	
</style>
<script type="text/javascript">
	/* 换片保存明细  */
	function changeImperfect(styleId) {
		/*  */
		//formatMoney($("#write"), 2);
		if ($("#sourceKbn").val() == "") {
			/* 请选择来源 */
			alert("<spring:message code='changeImperfect_alert_pleaseSelectSource'/>");
			return;
		}else if($("#write").val() == "" || $("#write").val() == "0.00" ){
			/* 请输入换片数量 */
			alert("<spring:message code='changeImperfect_alert_pleaseInputQuantity'/>");
			return;
		}
		/*  */
		var materialQuantity = $("#write").val().replace(',','');
		if ($("#sourceKbn").val() == "CHANGEIMPERFECT_SOURCE-MATERIAL_REMAIN") {
			if (parseFloat($("#remainQuantity").val()) < parseFloat(materialQuantity)) {
				/* 换片数量不能大于料头数量 */
				alert("<spring:message code='changeImperfect_alert_cannotMoreThanRemain'/>");
				return;
			}
		}else {
			if (parseFloat($("#inventoryQuantity").val()) < parseFloat(materialQuantity)) {
				/* 换片数量不能大于库存数量 */
				alert("<spring:message code='changeImperfect_alert_cannotMoreThanInventory'/>");
				return;
			}
		}
		var url = "${ctx}/saveChangeImperfect";
		params = {
			"orderId":$("#orderId").val(),
			"orderNo":$("#orderNo").val(),
			"contractId":$("#contractId").val(),
			"materialId":$("#materialId").val(),
			"materialQuantity":$("#write").val(),
			"sourceKbn":$("#sourceKbn").val(),
			"reworkReason":$("#reworkReason").val()
		}
		$.post(url,params,function(result){
			if (result == "true") {
				tipParent('换片成功');
				window.parent.$('#orderNo').focus();
				closeWin();
            } else {
            	tipParent('换片失败！');
            }
		});
	}
	/* 选择物料来源  */
	function selectSource(flag){
		if (flag == 0) {
			document.getElementById("inventoryBtn").style.background = "#595959";
			document.getElementById("stubBarBtn").style.background = "#DDDDDD";
			$("#sourceKbn").val("CHANGEIMPERFECT_SOURCE-MATERIAL_INVENTORY");
		}else if (flag == 1) {
			document.getElementById("inventoryBtn").style.background = "#DDDDDD";
			document.getElementById("stubBarBtn").style.background = "#595959";
			$("#sourceKbn").val("CHANGEIMPERFECT_SOURCE-MATERIAL_REMAIN");
		}
	}
</script>
</head>
<body>
<div>
<div style="width:100%;background:#595959;padding-left:20px;padding-bottom:10px;box-sizing:border-box;" class="topBtnClose">
<!-- 换片 -->
	<span style="font-size:35px;color:white;margin-top:20px;display:inline-block"><spring:message code='changeImperfect_title_changeImperfect'/></span>
</div>
<div class="smOrderBox" style="height: 60%;width: 65%;float: left;">
	<input type="hidden" id="orderId" value="${materialInfo.id}"/>
	<input type="hidden" id="orderNo" value="${materialInfo.orderNO}"/>
	<input type="hidden" id="contractId" value="${materialInfo.contractID}"/>
	<input type="hidden" id="materialId" value="${materialInfo.fabricId}"/>
	<input type="hidden" id="reworkReason" value="${reworkReason}"/>
	<div class="items clearfix" style="padding: 10px 0">
       	<div class="clearfix" style="font-size: 37px;left: 5%;position: relative;">
       	<!-- 面料名称 -->
            <p class="tit" style="width: 30%;"><spring:message code='changeImperfect_materialName'/>:</p>
            <p>${materialInfo.styleFabricNo}</p>
        </div>
	</div>
	<div class="items clearfix" style="padding: 10px 0">
       	<div class="clearfix" style="font-size: 37px;left: 5%;position: relative;">
       	<!-- 库存数量 -->
            <p class="tit" style="width: 30%;"><spring:message code='changeImperfect_inventoryQuantity'/>:</p>
            <p class="tit" style="width: 30%;"><fmt:formatNumber value="${inventoryQuantity }" pattern="#,##0.00"/></p>
            <input type="hidden" id="inventoryQuantity" value="${inventoryQuantity }"/>
        </div>
    </div>
   <div class="items clearfix" style="padding: 10px 0">
   		<div class="clearfix" style="font-size: 37px;left: 5%;position: relative;">
        <!-- 料头数量 -->
            <p class="tit" style="width: 30%;"><spring:message code='changeImperfect_remainQuantity'/>:</p>
            <p class="tit" style="width: 30%;">
            <c:choose>
	            <c:when test="${remainQuantity != null }">
		            <fmt:formatNumber value="${remainQuantity }" pattern="#,##0.00"/>
		            <input type="hidden" id="remainQuantity" value="${remainQuantity }"/>
	            </c:when>
	            <c:otherwise>
	            	<fmt:formatNumber value="0" pattern="#,##0.00"/>
	            	<input type="hidden" id="remainQuantity" value="0"/>
	            </c:otherwise>
	            </c:choose>
            </p>
        </div>
	</div>
	<div class="items clearfix" style="padding: 10px 0">
       	<div class="clearfix" style="font-size: 37px;left: 5%;position: relative;">
       	<!-- 来源 -->
            <p class="tit" style="width: 20%;top: 10px;position: relative;"><spring:message code='changeImperfect_source'/>:</p>
            <!-- 库存 -->
            <button id="inventoryBtn" style="width:150px;height: 50px;font-size: 32px;border:none;border-radius:5px;margin-bottom:10px;background:#DDDDDD;color:#ffffff;"  type="button" onclick="selectSource(0);"><spring:message code='changeImperfect_inventory'/></button>
            <!-- 料头 -->
            <button id="stubBarBtn" style="width:150px;height: 50px;font-size: 32px;border:none;border-radius:5px;margin-bottom:10px;background:#DDDDDD;color:#ffffff;"  type="button" onclick="selectSource(1);"><spring:message code='changeImperfect_remain'/></button>
        	<input type="hidden" id="sourceKbn" value=""/>
        </div>
	</div>
	<div class="items clearfix" style="padding: 10px 0">
       	<div class="clearfix" style="font-size: 37px;left: 5%;position: relative;">
       	<!-- 换片数量 -->
            <p class="tit" style="width: 30%;top: 13px;position: relative;"><spring:message code='changeImperfect_changeImperfectQuantity'/>:</p>
            <input style="font-size: 35px;width: 36%;height: 14%" type="text" onkeydown="keyLogin(event);"  onfocus="javascript:this.select();" id="write" value="" />
        </div>
	</div>
</div>
<div class="smOrderBox" style="height: 60%;width: 35%;float: left;">
    <div>
        <ul id="keyboard">
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>7</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>8</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>9</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>4</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>5</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>6</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>1</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>2</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>3</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>.</span></li>
            <li class="symbol" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;"><span>0</span></li>
            <li class="delete" style="margin: 0 10px 10px 0;width: 80px;height: 80px;font-size: 30px;">del</li>
        </ul>
    </div>
</div>
<div class="smOrderBox" style="height: 30%;width: 100%;float: left;">
	<div class="" style="left: 32%;top:20%;position: relative;">
	<!-- 确认 -->
		<button style="width:150px;height: 50px;font-size: 32px;border:none;border-radius:5px;margin-bottom:10px;background:#595959;color:#ffffff;"  type="button" value="${materialAll.styleIdList}" onclick="changeImperfect(this.value)"><spring:message code='changeImperfect_sure'/></button>
		<!-- 取消 -->
		&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;<button style="width:150px;height: 50px;font-size: 32px;border:none;border-radius:5px;margin-bottom:10px;background:#595959;color:#ffffff;"  type="button" value="${materialAll.styleIdList}" onclick="window.parent.$('#orderNo').focus();closeWin()"><spring:message code='changeImperfect_cancel'/></button>
	</div>
</div>
</div>
</body>
</html>